/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.p2psimulator.gui.auxiliar;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.p2psimulator.engine.Environment;
import org.p2psimulator.util.ProgressThread;

/**
 *
 * @author Amorim
 */
public class EnvironmentLoader extends ProgressThread{

    Environment enviroment;

    public EnvironmentLoader(Environment enviroment) {
        super(enviroment.TOTAL_ACTIVITY);
        this.enviroment = enviroment;
    }
    
    public Environment getEnviroment() {
        return enviroment;
    }

    public void setEnviroment(Environment enviroment) {
        this.enviroment = enviroment;
    }

    
    @Override
    public void runProcess() {

        new Thread(new Loader()).start();
        currentActivityNumber = enviroment.getCurrentActivity();

        while (currentActivityNumber < totalActivity){
            currentActivity = enviroment.getActivity();
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                Logger.getLogger(EnvironmentLoader.class.getName()).log(Level.SEVERE, null, ex);
            }
            currentActivityNumber = enviroment.getCurrentActivity();
        }
    }

    
    class Loader implements Runnable{

        public void run(){
            enviroment.load();
        }
    }

}
